-
Notifications
You must be signed in to change notification settings - Fork 28
/
example.py
95 lines (73 loc) · 2.17 KB
/
example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
from pygame.locals import *
import pygame
import sys
from random import randint, choice
from particle import *
sys.path.append('GUI')
from attributesGUI import GUI
pygame.init()
class Example():
def __init__(self):
pygame.display.set_caption('Platformer')
self.clock = pygame.time.Clock()
self.res = [640, 480]
self.FPS = 50
self.screen = pygame.display.set_mode(self.res)
self.font = pygame.font.SysFont("Calibri", 16)
self.pManager = ParticleManager()
self.GUI = GUI(self.screen, self)
self.attrs = {'shape' : 'circle',
'size': 6,
'density' : 6,
'speed' : 6}
self.defaults = self.attrs # save starting values
self.random = True
self.constant = False
self.hide = False
self.running = True
while self.running:
self.Loop()
def Loop(self):
self.clock.tick(self.FPS)
self.eventLoop()
self.Update()
pygame.display.update()
def getColor(self):
return [randint(0, 255) for _ in xrange(3)]
def eventLoop(self):
for event in pygame.event.get():
if not self.hide:
self.GUI.check_events(event)
if event.type == QUIT:
self.running = 0
pygame.quit()
elif event.type == KEYDOWN:
if event.key == 32:
if self.hide:
self.hide = False
else:
self.hide = True
if (event.type == MOUSEBUTTONDOWN and not self.constant) or (event.type == MOUSEMOTION and self.constant):
self.createParticles()
def createParticles(self):
pos = pygame.mouse.get_pos()
shape = choice(['circle', 'rect'])
if self.random:
self.pManager.new(pos, size=randint(4,7), density=randint(4,7), color=self.getColor(), shape=shape)
else:
self.pManager.new(pos, size=self.attrs['size'], density=self.attrs['density'], speed=self.attrs['speed'], color=self.getColor(), shape=self.attrs['shape'])
def updateAttributes(self):
if not self.random:
for key in self.attrs.keys():
try:
self.attrs[key] = int(self.GUI.textboxes[key].text)
except:
self.attrs[key] = self.defaults[key]
self.attrs['shape'] = self.GUI.s_Label.text.lower()
def Update(self):
self.screen.fill(0)
self.pManager.update(self.screen)
if not self.hide:
self.GUI.update()
self.updateAttributes()
Example()